1.code
import React, { useState } from 'react';
import styles from './ImageFollowMouse.module.css';
import Image from 'next/image';
function ImageFollowMouse() {
const [position, setPosition] = useState({ x: 0, y: 0 });
const handleMouseMove = (e) => {
setPosition({ x: e.clientX, y: e.clientY });
};
return (
<div
className={styles.container}
onMouseMove={handleMouseMove}
>
<div
className={styles.image}
style={{
left: position.x,
top: position.y,
}}
>
<Image src="/meme_00.png" alt="Follow Mouse" width={150} height={150} />
</div>
</div>
);
}
export default ImageFollowMouse;
2.實作